package com.yc.javaee.servlet.d0621;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

@WebServlet(name = "NextWeekServlet", value = "/nextWeek.s")
public class NextWeekServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        // 日期对象代表静态时间点
        Date date = new Date();
        // 日历
        Calendar cal = Calendar.getInstance();
        // 日期格式化工具
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd EEE");
        writer.append("当前时间: " + sdf.format(cal.getTime())).append("<br>");
        // 计算下周三   add 周数+1,  set 设置为周三
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
        writer.append("下周三: " + sdf.format(cal.getTime())).append("<br>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
